<script src="<?=baseinfo?>/js/vendor/binaryajax.js"></script>
<script src="<?=baseinfo?>/js/vendor/exif.js"></script>
<script src="<?=baseinfo?>/js/vendor/canvasResize.js"></script>
<script src="<?=baseinfo?>/js/vendor/jquery.Jcrop.min.js"></script>
<script src="<?=baseinfo?>/js/vendor/jquery.iuploader-1.0.js"></script>
<script src="<?=baseinfo?>/js/vendor/jsuri-1.1.1.js"></script>
<script src="<?=baseinfo?>/js/coreadd.js"></script>


<div class="ovlPopGen wrpPopViewReward" style="display: none;">
        <div class="popGen posPop">
            <div class="topGen clBd2 bdBtm">
                <div class="wrpTtlGen ">
                    <h1 class="ttlGen clTxt2 fs05 cutTxt">View Reward</h1>
                </div>
                <div class="btnIco closeGen" onclick="$('.wrpPopViewReward').fadeOut()">
                    <span class="ico icoCloseGen"></span>
                </div>
                <div class="topBgGen clBg3"></div>
            </div>
            <div class="bodyGen clBg3">
                <div class="bodyOutGen">
                    <div class="bodyInGen">
                        <div class="wrpFrmGen">
                            <div class="bodyRefNo fs04 clTxt2">
                                <div class="bdRefNo">
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Reward Image</span>
                                        <img width="100" height="100" class="pfImgPlg" alt="" src="img/dfthmbuser.jpg">
                                    </div>
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Title</span>
                                        <span class="rewardInfo title">Reward Title Reward Title Reward Title</span>
                                    </div>
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Description</span>
                                        <span class="rewardInfo desc">Reward Description</span>
                                    </div>
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Duration</span>
                                        <span class="rewardInfo dateset">10/10/2014 - 20/10/2014</span>
                                    </div>
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Total Amount</span>
                                        <span class="rewardInfo amount">10 Pieces</span>
                                    </div>
                                    <div class="inpRewardInfo clearfix">
                                        <span class="titleRewardInfo boldGen fs03">Amount per Day</span>
                                        <span class="rewardInfo perday">1 Pieces</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>    
            </div>
        </div>
    </div>
    


<link rel="stylesheet" href="<?=baseinfo?>/css/vendor/jcrop/jquery.Jcrop.min.css" type="text/css" />

<script>
var datarow; 
var setrownow=0;
function changetabdata(strdata)
{

if(strdata=='wrprRewardList')
{
    getactivitydatacenter(1) ;

}
if(strdata=='wrprPlayerAct')
{

getactivityrelatedatacenter(1) ;

}


$('.wrpInActMn').hide();
$('.'+strdata).show();

}
function clearinputdata()
{
$("#formpact :input").each(function(){
$(this).val('');
});

$("#formpact textarea").val('');
$("#formpact .imgBdgeGm").html('');

}
function saveactivitydatacenter()
{

if($('#formpact input[name="title"]').val()=='')
{
alertwrongboxmsgonly('Please Input Title');
return false;
}else if($('#formpact textarea[name="description"]').val()=='')
{

alertwrongboxmsgonly('Please Input Description');
return false;
}else if($('#formpact input[name="startdate"]').val()=='')
{

alertwrongboxmsgonly('Please Input Startdate');
return false;
}else if($('#formpact input[name="enddate"]').val()=='')
{

alertwrongboxmsgonly('Please Input Enddate');
return false;
}else if($('#formpact input[name="totalamount"]').val()=='')
{

alertwrongboxmsgonly('Please Input Totalamount');
return false;
}else if($('#formpact input[name="perday"]').val()=='')
{

alertwrongboxmsgonly('Please Input Perday');
return false;
}

$.post( serviceinfo+'saveactivitydatacenter',$('#formpact').serialize(), function( data ) {

alertrightboxmsgonly('Success');
clearinputdata();
$('.tgHdGen.tgCl.clBd2').removeClass('clSp2');
$('.tgHdGen.tgCl.clBd2:eq(1)').addClass('clSp2');
changetabdata('wrprRewardList');

});



}

function editactivitydatacenter()
{

if($('#formpactedit input[name="title"]').val()=='')
{
alertwrongboxmsgonly('Please Input Title');
return false;
}else if($('#formpactedit textarea[name="description"]').val()=='')
{

alertwrongboxmsgonly('Please Input Description');
return false;
}else if($('#formpactedit input[name="startdate"]').val()=='')
{

alertwrongboxmsgonly('Please Input Startdate');
return false;
}else if($('#formpactedit input[name="enddate"]').val()=='')
{

alertwrongboxmsgonly('Please Input Enddate');
return false;
}else if($('#formpactedit input[name="totalamount"]').val()=='')
{

alertwrongboxmsgonly('Please Input Totalamount');
return false;
}else if($('#formpactedit input[name="perday"]').val()=='')
{

alertwrongboxmsgonly('Please Input Perday');
return false;
}

$.post( serviceinfo+'saveactivitydatacenter',$('#formpactedit').serialize(), function( data ) {

alertrightboxmsgonly('Success');



getactivitydatacenter(1);


$('.wrpAddActReward').fadeOut();    

});



}

function viewactivity(rowdata)
{

var valuedata=datarow[rowdata-1]; 

$('.wrpPopViewReward .pfImgPlg').attr('src',valuedata.simg.newpath);
$('.wrpPopViewReward .rewardInfo.title').html(valuedata.title);
$('.wrpPopViewReward .rewardInfo.desc').html(valuedata.description);
$('.wrpPopViewReward .rewardInfo.dateset').html(valuedata.startdate+' - '+valuedata.enddate);
$('.wrpPopViewReward .rewardInfo.amount').html(valuedata.totalamount);
$('.wrpPopViewReward .rewardInfo.perday').html(valuedata.perday);
$('.wrpPopViewReward').fadeIn();


}

function editactivity(rowdata)
{
var valuedata=datarow[rowdata-1];
setrownow=rowdata-1;

$('.wrpAddActReward .imgTn').attr('src',valuedata.simg.newpath);




$('.wrpAddActReward input[name="title"]').val(valuedata.title);

$('.wrpAddActReward input[name="imgmid[]"]').val(valuedata.imgmid);
$('.wrpAddActReward input[name="simgmid[]"]').val(valuedata.simgmid);

$('.wrpAddActReward textarea[name="description"]').val(valuedata.description);
$('.wrpAddActReward input[name="startdate"]').val(valuedata.startdate);
$('.wrpAddActReward input[name="enddate"]').val(valuedata.enddate);
$('.wrpAddActReward input[name="totalamount"]').val(valuedata.totalamount);
$('.wrpAddActReward input[name="perday"]').val(valuedata.perday);
$('.wrpAddActReward input[name="rewardid"]').val(valuedata.rewardid);



$('.wrpAddActReward').fadeIn();  

}
function deleteactivity(id)
{
$.post( serviceinfo+'deleteactivitydatacenter',{rewardid:id}, function( data ) {

alertrightboxmsgonly('Success');
getactivitydatacenter(1);

});

}
function getactivitydatacenter(page)
{
var code='';
var krow=1;
var krowset=1;
$.get( serviceinfo+'getactivitydatacenter',{page:page}, function( data ) {
datarow=data.data;
if(data.data.length)
{

krowset=((page-1)*20);
         $.each(data['data'], function(key, value) {
krowset++;
code += '<div class="plyerLst clBd2 bdBtm clearfix">\n';
code += '<div class="ordAct clearfix">\n';
code += '<span>'+krowset+'.</span>\n';
code += '</div>\n';
code += '<div class="nmeReward clearfix">\n';
code += '<span class="cutTxt">'+value['title']+'</span>\n';
code += '</div>\n';
code += '<div class="dateAct clearfix">\n';
code += '<span>'+value['startdate']+'</span>\n';
code += '</div>\n';
code += '<div class="dateAct clearfix">\n';
code += '<span>'+value['enddate']+'</span>\n';
code += '</div>\n';
code += '<div class="btnActLst">\n';
code += '<button type="button" onclick="viewactivity('+krow+')" class="btnViewAct clTxtW clBgSp2 fs04">View</button>\n';
code += '<button type="button" onclick="editactivity('+krow+')" class="btnEditAct clTxtW clBgBt1 fs04">Edit</button>\n';
code += '<button type="button" onclick="boxconfirmmsgdata(\'Delete ?\',\'deleteactivity\','+value['rewardid']+')" class="btnDelAct clTxtW clBgBt1 fs04">Delete</button>\n';
code += '</div>\n';
code += '</div>';
           krow++;
           
         });

}



$('.wrprRewardList .bdPlyerLst').html(code);

if(page==1)
{
var param1,param2,param3;
setpaginationnoreverse('.pgActGame',data.count,20,'getactivitydatacenter',param1,param2,param3);
}

});


}


function getactivityrelatedatacenter(page)
{
var code='';
var krow=1;
var krowset=1;

$.get( serviceinfo+'getactivityrelatedatacenter',{page:page}, function( data ) {
datarow=data.data;
krowset=((page-1)*20);
if(data.data.length)
{

         $.each(data['data'], function(key, value) {


code += '<div class="plyerLst clBd2 bdBtm clearfix">\n';
code += '<div class="ordAct clearfix">\n';
code += '<span>'+(krowset+1)+'.</span>\n';
code += '</div>\n';
code += '<div class="dateAct clearfix">\n';
code += '<span>'+value['createdate']+'</span>\n';
code += '</div>\n';
code += '<div class="playerAct clearfix">\n';
code += '<a href="'+baseinfo+'/'+value['username']+'" target="_blank" class="clearfix">\n';
code += '<img width="24" height="24" class="genImgUser" src="'+value['simg']['newpath']+'" alt="img">\n';
code += '<span class="cutTxt">'+value['displayname']+'</span>\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="RewardPlayerAct clearfix">\n';
code += '<span>'+value['title']+'</span>\n';
code += '</div>\n';
code += '</div>\n';
            krowset++;
           krow++;
         });

}



$('.wrprPlayerAct .bdPlyerLst').html(code);

if(page==1)
{
var param1,param2,param3;
setpaginationnoreverse('.pgActGame2',data.count,20,'getactivityrelatedatacenter',param1,param2,param3);
}

});


}

function imageset(rowgnowset,widthset,heightset,widthset2,heightset2,settarget)
{

var settargetset='imgBdgeGm';
if(settarget)
{
settargetset=settarget;
}
var rownow=1;
var rowgnow=rowgnowset;
 
 $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(widthset,heightset,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];        
         $('#feature'+rownow+' .image'+rowgnow2+' .'+settargetset).html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);                 
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);      
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);      
         $("#imgmid-"+setting.id).val(setting.imgmid);       
         $("#simgmid-"+setting.id).val(imgmid2);               
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);    
         
          closepopup();  
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //console.log("testdata");
          //var rowgnow3=rowgnow;
          var rowgnow3=rowgnowset;
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 

        $('#feature'+rownow+' .image'+rowgnow3+' .'+settargetset).html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);

        closepopup();  

          
          },
          
          
          function(filename,filelink,width,height,imgmid,indexnow){
            
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+'  .deletebutton').click(function() {
   
   var rowgnow3=rowgnowset;
   

   $('#feature'+rownow+' .image'+rowgnow3+' .'+settargetset+' a').remove();
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=rowgnowset;
   //console.log("test");
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .'+settargetset).html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
        // $.colorbox.close("User added succesfully"); 
        closepopup();  
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            

            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
   );
   
   });
   
    $('#feature'+rownow+' .image'+rowgnow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();

});

}



var rownow=1;
$( document ).ready(function() {


imageset('datareward',600,600,150,150,'imgBdgeGm');

imageset('datarewardeAct2',600,600,150,150,'imgBdgeGm');


    
$('.wrpAddActReward input[name="startdate"]').datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$('.wrpAddActReward input[name="enddate"]').datepicker( "option", "minDate", selectedDate );
}
});

$('.wrpAddActReward input[name="enddate"]').datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$('.wrpAddActReward input[name="startdate"]').datepicker( "option", "maxDate", selectedDate );

}
});







$('.wrprCreateReward input[name="startdate"]').datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$('.wrprCreateReward input[name="enddate"]').datepicker( "option", "minDate", selectedDate );
}
});

$('.wrprCreateReward input[name="enddate"]').datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$('.wrprCreateReward input[name="startdate"]').datepicker( "option", "maxDate", selectedDate );

}
});
    
    

});

</script>